
#include "global.h"

unsigned int TimeCountCompuSpeed=0,TimeCountTemp=0,TimeCountSTDelay=0,Icount=0;
unsigned int TimeCountRealSpd=0,TimeCountPID=0,TimeCountAvgSpd=0,TimeCountVI=0,TimeCountStartUP=0;

unsigned char MOTORSTATE=STATESTARTCHECK;  

uint16_t SampleData[6];//母线电压 U反电动势 V反电动势  W反电动势 调速  电流  

unsigned char ErrorCode=0; //故障状态
unsigned int  Motor_Start_F=0; //电机启停状态
unsigned int  Cur_step=0; //当前换相相序
unsigned char Dir=0; //方向控制

unsigned int HALLcount=0,HALLcount1=0,HALLcountTemp; // 霍尔脉冲计数值，用于计算平均速度和瞬时速度
unsigned int TargS1=150;//PID目标速度
unsigned int RealS1=0;//实时瞬时速度
unsigned int RealS=0;//平均速度
unsigned int SetSpeed=0;
float KKN=0;//计算电位器速度时的斜率

unsigned int OutPwmValue=0;//输出占空比值
   

unsigned int SpeedD=0;//加速步序

unsigned int DIin=0; //电流偏置
unsigned int CanshuV=0;//母线电压100mV为单位
unsigned int CanshuI=0;//母线电流mA
 
unsigned int  MPolePairs=4;  //极对数
unsigned int  MINSPEED=200;  //最低转速
unsigned int  MAXSPEED=6000; //额定转速

unsigned int  CanshuTimeDelay=200;//启动延时间MS

unsigned int  ISH=30;//过流报警值 A
unsigned int  VSH=28;//过压报警值 V
unsigned int  LSH=10;//欠压报警值 V

//速度闭环参数  实际缩小1000倍
unsigned int  CanshuSTT=1000;//启动时间MS   时间参数 
    
unsigned int STEP_last=0;
 

long  aavsp=0;
unsigned int aacvsp=0;
long sumavsp=0;


unsigned int aa=0,bb=0,cc=0;
unsigned int aac=0,bbc=0,ccc=0;
unsigned int suma=0,sumb=0,sumc=0;

unsigned int bHallStartStep1;

unsigned int sumia=0,sumib=0,sumic=0;


unsigned int CanshuIA,CanshuIB,CanshuIC;//母线电流mA
